﻿using System.IO;
using Newtonsoft.Json;

namespace Kwan.Web
{
    public static class JsonResult<T> where T : Kwan.Data.Mappings.DataObject, new()
    {
        public static string ToList(string Data)
        {
            StringWriter sw = new StringWriter();
            JsonSerializer serializer = JsonSerializer.Create(
                new JsonSerializerSettings
                {
                    Converters = new JsonConverter[] { new Newtonsoft.Json.Converters.JavaScriptDateTimeConverter() },
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                    NullValueHandling = NullValueHandling.Ignore
                }
                );

            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {

                jsonWriter.Formatting = Formatting.Indented;
                serializer.Serialize(jsonWriter, Data);
            }
            return sw.ToString();
        }
    }
}
